package com.tiheima.service.impl;

import com.tiheima.mapper.ReportMapper;
import com.tiheima.model.dos.EmpJobDataDO;
import com.tiheima.model.dos.StudentCountOfClazzDataDO;
import com.tiheima.model.vo.report.GetEmpGenderDataVO;
import com.tiheima.model.vo.report.GetEmpJobDataVO;
import com.tiheima.model.vo.report.GetStudentCountOfClazzDataVO;
import com.tiheima.model.vo.report.GetStudentDegreeDataVO;
import com.tiheima.service.ReportService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {

    @Resource
    private ReportMapper reportMapper;

    @Override
    public GetEmpJobDataVO getEmpJobData() {
        List<EmpJobDataDO> list = reportMapper.getEmpJobData();
        GetEmpJobDataVO vos = new GetEmpJobDataVO();
        ArrayList<String> jobNames = new ArrayList<>();
        ArrayList<Integer> jobTotals = new ArrayList<>();
        for (EmpJobDataDO dos : list) {
            jobNames.add(dos.getJobName());
            jobTotals.add(dos.getTotal());
        }
        vos.setJobList(jobNames);
        vos.setDataList(jobTotals);
        return vos;
    }

    @Override
    public List<GetEmpGenderDataVO> getEmpGenderData() {
        return reportMapper.getGenderData();
    }

    @Override
    public List<GetStudentDegreeDataVO> getStudentDegreeData() {
        return reportMapper.getStudentDegreeData();
    }

    @Override
    public GetStudentCountOfClazzDataVO getStudentCountOfClazzData() {
        List<StudentCountOfClazzDataDO> list = reportMapper.getStudentCountOfClazzData();
        GetStudentCountOfClazzDataVO vos = new GetStudentCountOfClazzDataVO();
        ArrayList<String> clazzNames = new ArrayList<>();
        ArrayList<Integer> dataCounts = new ArrayList<>();
        for (StudentCountOfClazzDataDO dos : list) {
            clazzNames.add(dos.getClazzName() == null ? "其他" : dos.getClazzName());
            dataCounts.add(dos.getDataCount());
        }
        vos.setClazzList(clazzNames);
        vos.setDataList(dataCounts);
        return vos;
    }
}
